package com.lagou.interceptor;


import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 返回值boolean代表是否放⾏，true代表放⾏，false代表中⽌
        Object user = request.getSession().getAttribute("session_login");
        if (user == null) {
            response.sendRedirect(request.getContextPath() + "/page/login.htm");
            return false;
        }
        return true;
    }
}















